from map_state import PuzzleState, astar_search_for_puzzle_problem, run_moves, generate_moves, print_moves, convert_moves, runs
import numpy as np

def map_state_main(start,dst,map_size):

    # Create a initial state randomly
    # map_size = [3,5]

    init_state = PuzzleState(map_size=map_size)
    # dst = [1, 2, 3,
    #        8,-1, 6,
    #        7, 4, 5]
    # dst = [1,1,-1,1,1,
    #         1,0,-1,1,1,
    #         1,1,1,1,-2 ]
    # start = [1,-2,-1,1,1,
    #         1,0,-1,1,1,
    #         1,1,1,1,1 ]
    init_state.state = np.asarray(start).reshape(map_size[0], map_size[1])

    # move_list = generate_moves(100)
    # init_state.state = runs(init_state, move_list).state

    # Set a determined destination state
    dst_state = PuzzleState(map_size=map_size)
    dst_state.state = np.asarray(dst).reshape(map_size[0], map_size[1])

    # Find the path from 'init_state' to 'dst_state'
    move_list = astar_search_for_puzzle_problem(init_state, dst_state)

    move_list = convert_moves(move_list)

    # Perform your path
    if run_moves(init_state, dst_state, move_list):
        final_list=print_moves(init_state, move_list)
        print("Our dst state: ")
        dst_state.display()
        print("Get to dst state. Success !!!")
    else:
        print_moves(init_state, move_list)
        final_list=[]
        print("Our dst state: ")
        dst_state.display()
        print("Can not get to dst state. Failed !!!")
    return final_list
    print(final_list)
# map_state_main()